package com.dekarrin.scraton;

import com.dekarrin.util.StringPadder;
import com.dekarrin.util.StringWrapper;

public class ActionLine extends ScriptInstruction {

	private String action;
	
	public ActionLine(long timestamp, ScriptFormat format, String action) {
		super(timestamp, format);
		this.action = action;
	}
	
	public String toString() {
		int actionWidth = 0;
		String lineBreak = null;
		StringBuilder builder = new StringBuilder();
		if (format.indentActions) {
			String leftMargin = getClearLeftMargin();
			String rightMargin = getClearRightMargin();
			actionWidth = format.scriptWidth - (format.leftMarginWidth + format.rightMarginWidth);
			lineBreak = "\n" + leftMargin;
			builder.append(leftMargin);
		} else {
			actionWidth = format.scriptWidth;
			lineBreak = "\n";
		}
		StringWrapper wrapper = new StringWrapper(actionWidth, lineBreak);
		builder.append(wrapper.wrap(action));
		builder.append("\n\n");
		return builder.toString();
	}
}